import request from "./index";

//根据token值获取当前用户信息
export interface getUserAns {
    code: number;
    msg: string;
    data: object | Array<any>
}
export const getUser = () => {
    return request({
        url: '/user/getUser',
        method: 'get'
    })
}

//用户注册
export interface userRegAns {
    code: number;
    msg: string;
}
export const userReg = (userId: string,userName: string,userEmail: string,userPwd: string) => {
    return request({
        url: '/user/reg',
        method: 'post',
        data: {
            userId,
            userName,
            userEmail,
            userPwd
        }
    })
}

//用户登录,获取token
export interface userLoginAns {
    code: number;
    msg: string;
    token: string;
}
export const userLogin = (userEmail: string,userPwd: string) => {
    return request({
        url: '/user/login',
        method: 'post',
        data: {
            userEmail,
            userPwd
        }
    })
}

//用户修改用户名
export interface userChgNmsAns {
    code: number;
    msg: string;
    data: any;
}
export const userChgName = (newName: string) => {
    return request({
        url: '/user/changeName',
        method: 'get',
        params: {
            newName
        }
    })
}

//用户修改头像
export interface userChgAvaAns {
    code: number;
    msg: string;
    data: any;
}
export const userChgAva = (formData: object) => {
    return request({
        url: '/user/changeAva',
        method: 'post',
        data: formData
    })
}

//用户修改密码
export interface userChgPwdAns {
    code: number;
    msg: string;
    data: any
}
export const userChgPwd = (userPwd: string,newPwd: string) => {
    return request({
        url: '/user/changePwd',
        method: 'post',
        data: {
            userPwd,
            newPwd
        }
    })
}